Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autolocation of node-gyp in make-spawn-args #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legobeat
Copy link

@legobeat legobeat commented Sep 30, 2024

  • Prevents runtime error in environments where require.resolve is not available.
  • Fall back to environment variable npm_config_node_gyp when node-gyp not resolved successfully.

Related

@legobeat legobeat force-pushed the safe-require-resolve branch 3 times, most recently from 18186ac to ceef07a Compare September 30, 2024 00:32
@legobeat legobeat marked this pull request as ready for review September 30, 2024 00:32
@legobeat legobeat requested a review from a team as a code owner September 30, 2024 00:32
@legobeat legobeat changed the title fix: defensive autolocation of node-gyp in make-spawn-args fix: autolocation of node-gyp in make-spawn-args Sep 30, 2024
let npm_config_node_gyp
try {
/* istanbul ignore next */
if (typeof require === 'function' && typeof require.resolve === 'function') {
Copy link
Author

@legobeat legobeat Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeof require may seem redundant here considering we call require('path') just prior.

Rightfully or not, bundlers like webpack and esbuild may transform the direct require() calls but leave require.resolve intact. The extra check prevents runtime errors in such scenarios.

prevents runtime error in environments where `require.resolve` is not
available

Fall back to any existing `npm_config_node_gyp` provided by environment
@legobeat
Copy link
Author

legobeat commented Oct 3, 2024

@reggi @hashtagchris Some attention on this and #222 would be much appreciated if you are able to 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant